<?php
/*
	插件接口增删查改
*/
defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['plugin_id']){
	$_SESSION['plugin_id']=intval($_RQ['plugin_id']);
}
if(!$_SESSION['plugin_id']){
	exi('请先选择插件！','error');
}
if($_RQ['op']=='list'){
	$params=array('plugin_id'=>$_SESSION['plugin_id']);
	$result=cloud_request('plugin.func.list',$params);
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			'0'=>array('op'=>'list','title'=>'接口函数列表'),
			'1'=>array('op'=>'edit','title'=>'添加接口函数'),
		),
		'list'=>array('data'=>'list','no_del'=>false,'del_message'=>'确认删除吗？','del_op'=>'del','html_to'=>'list_html','show'=>array(
			'0'=>array('name'=>'name','title'=>'接口函数标识','type'=>'string'),
			'1'=>array('name'=>'title','title'=>'接口函数名称','type'=>'string'),
			'2'=>array('name'=>'type','title'=>'数据表类型','type'=>'radio','options'=>'types'),
		)),
		'search_one'=>array('name'=>'title','help'=>''),
	);
	$result['htmls']=$htmls;
	exi($result);
}
if($_RQ['op']=='edit'){
	$params=array('plugin_id'=>$_SESSION['plugin_id']);
	$id=intval($_RQ['id']);
	if($id){
		$params['id']=$id;
	}
	$result=cloud_request('plugin.func.edit',$params);
	exi($result);
}
if($_RQ['op']=='post'){
	$params=array('plugin_id'=>$_SESSION['plugin_id']);
	$post=get_postdata();
	$params['postdata']=base64_encode(json_encode($post));
	$result=cloud_request('plugin.func.post',$params);
	exi($result);
}
if($_RQ['op'] == 'del'){
	$params=array('plugin_id'=>$_SESSION['plugin_id']);
	if($_RQ['id']){
		$params['id']=intval($_RQ['id']);
	}
	if($_RQ['del']){
		$params['del']=trim($_RQ['del']);
	}
	$result=cloud_request('plugin.func.del',$params);
	exi($result);
}